package com.tony.study.designMode.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 *
 * @Title: DateUtils
 * @Auther: 皮蛋布丁
 * @Date: 2021/11/01/17:54
 * @Description:
 */
public class DateUtils {

    private static SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");

    public static String dateTostring(Date date) {
        return format.format(date);
    }

    /**
    * @Description: getTime 截取时间戳
    * @Param: [time]
    * @return: java.lang.Long
    * @Author: 皮蛋布丁
    * @Date: 2021/11/1 17:55
    */
    public static  Long getTime(long time){
        String timeStr = String.valueOf(time);
        int len = timeStr.length();
        if(len == 13){
            // 截取到秒
            timeStr = timeStr.substring(0, len-3);
        }
        return  Long.parseLong(timeStr);
    }

    public static Date addDays(Integer day){
        Calendar c = Calendar.getInstance();
        c.add(Calendar.DAY_OF_MONTH, day);
        return c.getTime();
    }
}
